/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.factory.web.backing;

/**
 *
 * @author milos
 */
import com.factory.web.dto.UserTaskDTO;
import com.factory.web.service.FactoryServiceInterface;
import java.io.InputStream;
import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;

import org.primefaces.model.DefaultStreamedContent;
import org.primefaces.model.StreamedContent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class FileDownloadController {

    @Autowired
    FactoryServiceInterface factoryService;
    private StreamedContent file;

    public StreamedContent handleDownload(UserTaskDTO userTaskDTO) {
        InputStream stream = factoryService.getResultFile(userTaskDTO.getInputId());
        file = new DefaultStreamedContent(stream, "text/txt", userTaskDTO.getUserId() + "-" + userTaskDTO.getProblemId());
        return file;
    }
}
